﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataAccess;
using DevComponents.DotNetBar.Controls;

namespace QUANLYKHACHSAN_N4
{
    public partial class frmQuanLyPhong : DevComponents.DotNetBar.Office2007RibbonForm
    {
        public frmQuanLyPhong()
        {
            InitializeComponent();
        }

        private void frmQuanLyPhong_Load(object sender, EventArgs e)
        {
            try
            {
                dgrLoaiPhong.DataSource = LoaiPhong_Info.All();
                dgrPhong.DataSource = Phong_Info.AllName().Tables[0];
                XuLyDataGridView.Style(new DataGridViewX[] { dgrPhong, dgrLoaiPhong, dgrThietBi });
                //dgrThietBi.Columns.Add(XuLyDataGridView.CotCombo("Thiết Bị", ThietBi_info.All(), "tentb", "tentb","TÊN THIẾT BỊ"));
                //XuLyDataGridView.dgrMouseMove(dgrLoaiPhong);
                //XuLyDataGridView.dgrMouseMove(dgrPhong);
                //XuLyDataGridView.dgrMouseMove(dgrThietBi);
                //XuLyDataGridView.AddCotButtom(dgrPhong, "XÓA", 20);

                dgrPhong.CellMouseClick += new DataGridViewCellMouseEventHandler(dgrPhong_CellMouseClick);
            }
            catch (Exception)
            {

            }
        }

        void dgrPhong_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            try
            {

                // DataGridView v = sender as DataGridView;
                if (e.ColumnIndex == 0)
                {
                    DgResul.ShowDiag("Đã xóa xong phong ");
                }
            }
            catch (Exception)
            {

            }
        }

        private void panel1_SizeChanged(object sender, EventArgs e)
        {
            grPhong.Width = grThietBi.Width = grLoaiPhong.Width = panel1.Width / 3 - 10;
        }

        private void dgrLoaiPhong_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            try
            {
                dgrThietBi.DataSource = ThietBi_info.GetByMaLoaiPhong(dgrLoaiPhong.CurrentRow.Cells["TENLOAIPHONG"].Value.ToString()).Tables[0];
                grThietBi.Text = "QUẢN LÝ THIẾT BỊ CỦA PHÒNG " + dgrLoaiPhong.CurrentRow.Cells["TENLOAIPHONG"].Value.ToString();
            }
            catch (Exception)
            {
            }
        }

        private void btnThemPhong_Click(object sender, EventArgs e)
        {
            frmThemSuaPhong frm = new frmThemSuaPhong();
            frm.Text = "Thêm Phòng";
            frm.ShowDialog();
        }

        private void btnSuaPhong_Click(object sender, EventArgs e)
        {
            try
            {
                frmThemSuaPhong frm = new frmThemSuaPhong();
                frm.Text = "Sửa Phòng";
                frm.txtTenPhong.Text = frm.ten = dgrPhong.CurrentRow.Cells["TENPHONG"].Value.ToString();
                DuLieu.GetValueInCombo(dgrPhong.CurrentRow.Cells["LOAIPHONG"].Value.ToString(), frm.cbLoaiPhong);
                if (
                frm.ShowDialog() != DialogResult.Cancel)
                    frmQuanLyPhong_Load(null, null);
            }
            catch (Exception)
            {

            }
        }

        private void btnDelAll_Click(object sender, EventArgs e)
        {
            if (DgResul.ShowDiag("Bạn có muốn xóa những phòng đã chọn", true))
            {
            }
        }

        private void btnThemLoaiPhong_Click(object sender, EventArgs e)
        {
            frmThemSuaLoaiPhong frm = new frmThemSuaLoaiPhong();
            frm.Text = "Thêm Loại Phòng";
            frm.ShowDialog();
        }

        private void btnSuaLoaiPhong_Click(object sender, EventArgs e)
        {
            try
            {
                frmThemSuaLoaiPhong frm = new frmThemSuaLoaiPhong();
                frm.Text = "Sửa Loại Phòng";
                frm.txtTenLoaiPhong.Text = frm.ten = dgrLoaiPhong.CurrentRow.Cells["TENLOAIPHONG"].Value.ToString();
                frm.txtSoNguoi.Text = dgrLoaiPhong.CurrentRow.Cells["SONGUOI"].Value.ToString();
                frm.txtGia.Text = dgrLoaiPhong.CurrentRow.Cells["GIA"].Value.ToString();
                frm.txtTenLoaiPhong.Enabled = false;
                if (frm.ShowDialog() != DialogResult.Cancel)
                    frmQuanLyPhong_Load(null, null);
            }
            catch (Exception)
            {

            }
        }

        private void btnThemThietBi_Click(object sender, EventArgs e)
        {
            frmThemSuaThietBi frm = new frmThemSuaThietBi();
            frm.Text = "Thêm Thiết Bị";
            frm.ShowDialog();
        }

        private void btnSuaThietBi_Click(object sender, EventArgs e)
        {
            try
            {
                frmThemSuaThietBi frm = new frmThemSuaThietBi();
                frm.Text = "Sửa Thiết Bị";
                frm.ten = dgrThietBi.CurrentRow.Cells["TENTHIETBI"].Value.ToString();
                DuLieu.GetValueInCombo(frm.ten, frm.cbThietBi);
                frm.txtSoLuong.Text = dgrThietBi.CurrentRow.Cells["SOLUONG"].Value.ToString();
                if (frm.ShowDialog() != DialogResult.Cancel)
                    frmQuanLyPhong_Load(null, null);
            }
            catch (Exception)
            {

            }
        }



    }
}
